﻿using System;
using System.Xml.Linq;

namespace YArchitech.Temp
{
	public class HYTerminal : HYMEPObject, IHYXmlSerial
	{
		public double Resistance { get; set; }

		public double PressureDrop { get; set; }

		public double DynamicPressure { get; set; }

		public override void SetNext(HYMEPObject nextObj)
		{
			this.m_NextObject = null;
		}

		public virtual HYPipeline GetHostPipeline()
		{
			if (this.m_HostPipeline != null)
			{
				return this.m_HostPipeline;
			}
			HYMEPObject previous = base.Previous;
			while (previous != null && !(previous is HYPipeline))
			{
				previous = previous.Previous;
			}
			if (previous == null)
			{
				return null;
			}
			this.m_HostPipeline = (previous as HYPipeline);
			return this.m_HostPipeline;
		}

		public override void Cal(HYSystemOption option)
		{
			HYPipeline hostPipeline = this.GetHostPipeline();
			if (hostPipeline == null)
			{
				return;
			}
			hostPipeline.AddAttachedObject(this, base.Name, this.Resistance, true, 0);
		}

		public override void ReadXml(XElement xe)
		{
			base.ReadXml(xe);
			this.Resistance = xe.GetDoubleAttribute("Resistance", 0.0);
			this.PressureDrop = xe.GetDoubleAttribute("PressureDrop", 0.0);
			this.DynamicPressure = xe.GetDoubleAttribute("DynamicPressure", 0.0);
		}

		public override void WriteXml(XElement xe)
		{
			base.WriteXml(xe);
			xe.SetAttributeValue("Resistance", this.Resistance);
			xe.SetAttributeValue("PressureDrop", this.PressureDrop);
			xe.SetAttributeValue("DynamicPressure", this.DynamicPressure);
		}

		protected HYPipeline m_HostPipeline;
	}
}
